#ifndef __MAX7219_DOT_MATRIX_H
#define __MAX7219_DOT_MATRIX_H

// ########################################################################################################
// PORTABLE
#include "_config_cpu_.h"
#include "_config_cpu_spi.h"

#if (MAX7219_USE_SPI == 1)
	#if defined(cortexm3)
	#include "ssp1.h"
	#define max7219_TransferByte(c)	ssp1_TransferByte(c)
	#else
	#include "spi1.h"
	#define max7219_TransferByte(c)	spi1_TransferByte(c)
	#endif

#elif (MAX7219_USE_SPI == 0)
	#if defined(cortexm3)
	#include "ssp0.h"
	#define max7219_TransferByte(c)	ssp0_TransferByte(c)
	#else
	#include "spi0.h"
	#define max7219_TransferByte(c)	spi0_TransferByte(c)
	#endif
#else
	#error NÃO FOI DEFINIDO A PORTA SPI PARA O MAX7219 EM _config_cpu_spi.h
#endif

#define max7219_SetupPorts()	{ MAX7219_CS_DIR |= MAX7219_CS; ILI9341_CMD_DIR |= ILI9341_CMD;}
#define max7219_Enable() 		MAX7219_CS_CLR =  MAX7219_CS 			// CS = 0 ativar o driver
#define max7219_Disable()  		MAX7219_CS_SET =  MAX7219_CS 			// CS = 1 desativar o driver

// ########################################################################################################
// FUNCTIONS
int max7219_Init(uint nModule);
int max7219_SetScanLimit(uint addr, uint limit);
int max7219_Shutdown(uint addr, u8 st);
int max7219_DisplayTest(uint addr, u8 st);
int max7219_SetBrightness(uint addr, u8 brightness);
	#define max7219_INTENSITY_MIN     0x00                        // minimum display intensity
	#define max7219_INTENSITY_MAX     0x0f                        // maximum display intensity
int max7219_Clear(uint addr);
int max7219_SetLed(uint addr, uint row, uint column, int state);
int max7219_SetRow(uint addr, uint row, u8 value);
int max7219_SetColumn(uint addr, uint col, u8 value);
int max7219_SetDigit(uint addr, int digit, u8 value, u8 dp);
int max7219_SetChar(int addr, char value, u8 dp);

#endif
